package com.lagou;

import com.lagou.bean.ConsumerComponent;
import com.lagou.runnable.ConsumerRunnable;
import com.lagou.runnable.Report;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ConsumerMain {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        //输出运行结果
        Executors.newSingleThreadScheduledExecutor()
                .scheduleWithFixedDelay(new Report(), 5,5, TimeUnit.SECONDS);

        //创建线程池进行调用服务
        ConsumerComponent service = context.getBean(ConsumerComponent.class);
        Executor executor1 = Executors.newFixedThreadPool(10);
        executor1.execute(new ConsumerRunnable(service, "A"));

        Executor executor2 = Executors.newFixedThreadPool(10);
        executor2.execute(new ConsumerRunnable(service, "B"));

        Executor executor3 = Executors.newFixedThreadPool(10);
        executor3.execute(new ConsumerRunnable(service, "C"));
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan("com.lagou.bean")
    @EnableDubbo()
    static class ConsumerConfiguration{

    }
}
